package com.lee.boot.batch.config;

import com.lee.boot.batch.model.Product;
import com.lee.boot.batch.model.ProductDO;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.ItemReader;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Date;

/**
 * @author: Lee
 * @Date: 2019/12/29 0029 11:49
 * @Description:
 */
@Configuration
@EnableBatchProcessing
public class JobConfig {

    @Autowired
    StepBuilderFactory stepBuilderFactory;
    @Autowired
    JobBuilderFactory jobBuilderFactory;

    @Bean("fileStep")
    public Step getStep(@Qualifier("fileReader") ItemReader itemReader, @Qualifier("fileProcessor") ItemProcessor<Product, ProductDO> itemProcessor,
                        @Qualifier("fileWriter") ItemWriter itemWriter) {
        return stepBuilderFactory.get("aaaa").<Product, ProductDO>chunk(1).reader(itemReader).processor(itemProcessor).writer(itemWriter).build();
    }

    @Bean("fileJob")
    public Job getJob(Step fileStep) {
        return jobBuilderFactory.get("1333123").start(fileStep).build();
    }
}
